package threadLocal;

/**
 * @author 帅小伙
 * @date 2022/3/13
 * @description
 */
public class Demo01 {

    ThreadLocal<String> threadLocal = new ThreadLocal<>();

    private  String content;

    public String getContent() {
        //return content;
        return threadLocal.get();
    }

    public void setContent(String content) {
       // this.content = content;
        threadLocal.set(content);
    }

    public static void main(String[] args) {
        Demo01 demo = new Demo01();

        //会获取到其他线程的数据
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                demo.setContent(Thread.currentThread().getName()+"的数据");
                System.out.println("---------");
                System.out.println(Thread.currentThread().getName()+"---->"+demo.getContent());
            },"线程"+i).start();
        }
    }

}
